package section_10.wildcardCahracter;

import java.util.ArrayList;
import java.util.List;

public class CovariantArrays {

	public static void main(String[] args) {
		Fruit[] fruit = new Apple[10];
		fruit[0] = new Apple();
		fruit[1] = new Jonathan();
		try {
			fruit[0] = new Fruit();
		} catch (Exception e) {
			System.out.println(e);
		}

		try {
			fruit[1] = new Orange();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
//		Compile error: imcompatible types:
//		List<Fruit> list = new ArrayList<Apple>();
		
		// Wildcards allow covariance
		List<? extends Fruit> flist = new ArrayList<Apple>();
		
		//Compile Error: can't add any type of object
//		flist.add(new Apple());
//		flist.add(new Fruit());
		
		flist.add(null);//Legal but uninteresting
		
	}
}

class Fruit {
}

class Apple extends Fruit {
}

class Jonathan extends Apple {
}

class Orange extends Fruit {
}